From 4dd32e2c0231d827f203e1407fa48070554d43f5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 23 Jul 2026 12:02:04 +0200 Subject: [PATCH] ibusManager: Avoid reusing a renewed cancellable across async calls When the shared cancellable gets renewed, in-flight async requests can end up using the wrong instance. Pass a stable cancellable per operation so each request stays bound to the cancellable it started with. Part-of: (cherry picked from commit ecbfbcb78e25b342687623c52e17c413a4263315) --- js/misc/ibusManager.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/js/misc/ibusManager.js b/js/misc/ibusManager.js index d9995b81a..0e76a13fc 100644 --- a/js/misc/ibusManager.js +++ b/js/misc/ibusManager.js @@ -160,14 +160,14 @@ class IBusManager extends Signals.EventEmitter { _onConnected() { this._cancellable = new Gio.Cancellable(); - this._initEngines(); - this._initPanelService(); + this._initEngines(this._cancellable); + this._initPanelService(this._cancellable); } - async _initEngines() { + async _initEngines(cancellable) { try { const enginesList = - await this._ibus.list_engines_async(-1, this._cancellable); + await this._ibus.list_engines_async(-1, cancellable); for (let i = 0; i < enginesList.length; ++i) { const name = enginesList[i].get_name(); this._engines.set(name, enginesList[i]); @@ -179,10 +179,10 @@ class IBusManager extends Signals.EventEmitter { } } - async _initPanelService() { + async _initPanelService(cancellable) { try { await this._ibus.request_name_async(IBus.SERVICE_PANEL, - IBus.BusNameFlag.REPLACE_EXISTING, -1, this._cancellable); + IBus.BusNameFlag.REPLACE_EXISTING, -1, cancellable); } catch (e) { if (logErrorUnlessCancelled(e)) this._clear(); @@ -220,7 +220,7 @@ class IBusManager extends Signals.EventEmitter { try { // If an engine is already active we need to get its properties const engine = - await this._ibus.get_global_engine_async(-1, this._cancellable); + await this._ibus.get_global_engine_async(-1, cancellable); this._engineChanged(this._ibus, engine.get_name()); } catch { } @@ -279,10 +279,11 @@ class IBusManager extends Signals.EventEmitter { if (!this._ready) return; + const cancellable = this._cancellable; try { await this._ibus.set_global_engine_async(id, this._MAX_INPUT_SOURCE_ACTIVATION_TIME, - this._cancellable); + cancellable); } catch (e) { if (!logErrorUnlessCancelled(e)) return; @@ -290,7 +291,7 @@ class IBusManager extends Signals.EventEmitter { try { await this._ibus.set_global_engine_async(FALLBACK_ENGINE_ID, this._MAX_INPUT_SOURCE_ACTIVATION_TIME, - this._cancellable); + cancellable); } catch (e2) { logErrorUnlessCancelled(e2); } -- 2.39.5